﻿namespace SupportSystemUI.Controls.CustomPages.Crew
{
    using System.Collections.Generic;
    using System.Windows.Controls;
    using System.Windows.Media;
    using SupportSystemDB;
    using SupportSystemUI.Controls.Pages;

    /// <summary>
    /// Interaction logic for ViewMembersItem.xaml
    /// </summary>
    public partial class ViewMembersItem : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewMembersItem"/> class.
        /// </summary>
        /// <param name="eventId">Id of this event.</param>
        public ViewMembersItem(int eventId)
        {
            this.InitializeComponent();

            this.MouseEnter += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
            };
            this.MouseLeave += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Colors.White);
            };
            this.MouseUp += (sender, args) =>
            {
                Global.Instance.PagesScreen.Push(
                    () => AppController.Instance.Members.GetMembers(eventId),
                    this.EventMembersView);
            };
        }

        /// <summary>
        /// Converts the database object into a viewable control.
        /// </summary>
        /// <param name="data">Data object.</param>
        /// <returns>A PageData object.</returns>
        private PageData EventMembersView(object data)
        {
            StackPanel panel = new StackPanel();
            foreach (vMember member in data as List<vMember>)
            {
                panel.Children.Add(new MemberItem(member));
            }
            
            return new PageData(panel, "Members List");
        }
    }
}
